home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / os2 / octa209s.zip / octave-2.09 / liboctave / DASSL.h < prev    next >
C/C++ Source or Header  |  1996-07-24  |  4KB  |  168 lines

  1. /*
  2.  
  3. Copyright (C) 1996 John W. Eaton
  4.  
  5. This file is part of Octave.
  6.  
  7. Octave is free software; you can redistribute it and/or modify it
  8. under the terms of the GNU General Public License as published by the
  9. Free Software Foundation; either version 2, or (at your option) any
  10. later version.
  11.  
  12. Octave is distributed in the hope that it will be useful, but WITHOUT
  13. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  14. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  15. for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with Octave; see the file COPYING.  If not, write to the Free
  19. Software Foundation, 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. */
  22.  
  23. #if !defined (octave_DASSL_h)
  24. #define octave_DASSL_h 1
  25.  
  26. #if defined (__GNUG__)
  27. #pragma interface
  28. #endif
  29.  
  30. #include <cfloat>
  31. #include <cmath>
  32.  
  33. #include "DAE.h"
  34.  
  35. class
  36. DASSL_options
  37. {
  38. public:
  39.  
  40.   DASSL_options (void) { init (); }
  41.  
  42.   DASSL_options (const DASSL_options& opt) { copy (opt); }
  43.  
  44.   DASSL_options& operator = (const DASSL_options& opt)
  45.     {
  46.       if (this != &opt)
  47.     copy (opt);
  48.  
  49.       return *this;
  50.     }
  51.  
  52.   ~DASSL_options (void) { }
  53.  
  54.   void init (void)
  55.     {
  56.       double sqrt_eps = sqrt (DBL_EPSILON);
  57.       x_absolute_tolerance = sqrt_eps;
  58.       x_initial_step_size = -1.0;
  59.       x_maximum_step_size = -1.0;
  60.       x_minimum_step_size = 0.0;
  61.       x_relative_tolerance = sqrt_eps;
  62.     }
  63.  
  64.   void copy (const DASSL_options& opt)
  65.     {
  66.       x_absolute_tolerance = opt.x_absolute_tolerance;
  67.       x_initial_step_size = opt.x_initial_step_size;
  68.       x_maximum_step_size = opt.x_maximum_step_size;
  69.       x_minimum_step_size = opt.x_minimum_step_size;
  70.       x_relative_tolerance = opt.x_relative_tolerance;
  71.     }
  72.  
  73.   void set_default_options (void) { init (); }
  74.  
  75.   void set_absolute_tolerance (double val)
  76.     { x_absolute_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); }
  77.  
  78.   void set_initial_step_size (double val)
  79.     { x_initial_step_size = (val >= 0.0) ? val : -1.0; }
  80.  
  81.   void set_maximum_step_size (double val)
  82.     { x_maximum_step_size = (val >= 0.0) ? val : -1.0; }
  83.  
  84.   void set_minimum_step_size (double val)
  85.     { x_minimum_step_size = (val >= 0.0) ? val : 0.0; }
  86.  
  87.   void set_relative_tolerance (double val)
  88.     { x_relative_tolerance = (val > 0.0) ? val : ::sqrt (DBL_EPSILON); }
  89.  
  90.   double absolute_tolerance (void) { return x_absolute_tolerance; }
  91.  
  92.   double initial_step_size (void) { return x_initial_step_size; }
  93.  
  94.   double maximum_step_size (void) { return x_maximum_step_size; }
  95.  
  96.   double minimum_step_size (void) { return x_minimum_step_size; }
  97.  
  98.   double relative_tolerance (void) { return x_relative_tolerance; }
  99.  
  100. private:
  101.  
  102.   double x_absolute_tolerance;
  103.   double x_initial_step_size;
  104.   double x_maximum_step_size;
  105.   double x_minimum_step_size;
  106.   double x_relative_tolerance;
  107. };
  108.  
  109. class
  110. DASSL : public DAE, public DASSL_options
  111. {
  112. public:
  113.  
  114.   DASSL (void);
  115.  
  116.   DASSL (const ColumnVector& x, double time, DAEFunc& f);
  117.  
  118.   DASSL (const ColumnVector& x, const ColumnVector& xdot,
  119.      double time, DAEFunc& f);
  120.  
  121.   ~DASSL (void) { }
  122.  
  123.   void force_restart (void);
  124.  
  125.   void set_stop_time (double t);
  126.   void clear_stop_time (void);
  127.  
  128.   ColumnVector do_integrate (double t);
  129.  
  130.   Matrix do_integrate (const ColumnVector& tout);
  131.  
  132.   Matrix integrate (const ColumnVector& tout, Matrix& xdot_out);
  133.  
  134.   Matrix integrate (const ColumnVector& tout, Matrix& xdot_out,
  135.             const ColumnVector& tcrit); 
  136.  
  137. private:
  138.  
  139.   double stop_time;
  140.   int stop_time_set;
  141.  
  142.   int n;
  143.   int integration_error;
  144.   int restart;
  145.   int liw;  
  146.   int lrw;
  147.   int idid;
  148.   int sanity_checked;
  149.   Array<int> info;
  150.   Array<int> iwork;
  151.   Array<double> rwork;
  152.  
  153.   friend int ddassl_j (double *time, double *state, double *deriv,
  154.                double *pd, double *cj, double *rpar, int *ipar);
  155.  
  156.   friend int ddassl_f (double *time, double *state, double *deriv,
  157.                double *delta, int *ires, double *rpar, int *ipar);
  158.  
  159. };
  160.  
  161. #endif
  162.  
  163. /*
  164. ;;; Local Variables: ***
  165. ;;; mode: C++ ***
  166. ;;; End: ***
  167. */
  168.